/*''加***************************
''重点材料逆向追踪程序2013.3.28 BACK()
''回交种系谱编制程序2013.3.28 BACKCROSS()
''杂种加代 将F1直接改成Fn F1ADD()
''*****************************
''
''加程序##################
''重点材料逆向追踪程序
''播始历期计算程序
''有效积温计算程序,将每年的有效积温数据以数组保存,一年一更新!!!
''##################加程序
*/
function 自交材料加季码(){
var i , j ;
var s2 = "2E";
for (var i=1;i<=4;i++)
{
if(Sheets.Item("current").Cells.Item(i, 2).Value2)var s1 = Sheets.Item("current").Cells.Item(i, 2).Value2;else var s1="";
//alert(s1);
if(s1 !="" && s1.indexOf(s2)< 0 ) Sheets.Item("current").Cells.Item(i, 2).Value2 = s2 + s1 ;
//alert(Sheets.Item("current").Cells.Item(i, 2).Value2);
s1 = Sheets.Item("current").Cells.Item(i, 3).toString() ;
// alert(s1);
if (s1 !="" && s1.indexOf(s2)< 0 && s1!="@" ) Sheets.Item("current").Cells.Item(i, 3).Value2 = s2 + s1 ;
// alert(Sheets.Item("current").Cells.Item(i, 2).Value2);
}
}
function 成对杂交简化录入() //right 2013.03.18
{
//处理仅录入当季不含季码编号且杂交种仅录母本号,父本仅录简单编号于父本列
var s1, s2, s3 = "2E";
for (var i = 1542;i<=1543;i+=2)
{
if(Sheets.Item("current").Cells.Item(i, 2).Value2)var s1 = Sheets.Item("current").Cells.Item(i, 2).Value2;else var s1="";
if(Sheets.Item("current").Cells.Item(i+1, 2).Value2)var s2 = Sheets.Item("current").Cells.Item(i, 2).Value2;else var s2="";
if(s1 !="" && s2 !="")
{
if(s1.indexOf(s3)< 0)
{
Sheets.Item("current").Cells.Item(i, 2).Value2 = s3+s1;
Sheets.Item("current").Cells.Item(i, 3).Value2 = s3+s2;
Sheets.Item("current").Cells.Item(i + 1, 2).Value2 = s3+s2;
Sheets.Item("current").Cells.Item(i + 1, 3).Value2 = "";
}
else
{
Sheets.Item("current").Cells.Item(i, 2).Value2 = s1;
Sheets.Item("current").Cells.Item(i, 3).Value2 = s2;
Sheets.Item("current").Cells.Item(i + 1, 2).Value2 = s2
Sheets.Item("current").Cells.Item(i + 1, 3).Value2 = "";
}
}
}
}
function 二十行加线()
{
for(var i=1;i<2001;i+=20)
{
Range("A"+i+":F"+i).Select();
Application.CutCopyMode = false;
(obj=>{
obj.Weight = xlMedium;
obj.LineStyle = xlContinuous;
obj.ColorIndex = xlColorIndexAutomatic;
})(Selection.Borders.Item(xlEdgeBottom));
}
}
function 杂交种加代(i, nameandhistory)
{
var s1, s2, s3 ;
var s = "F1" ;
if( Sheets.Item("current").Cells.Item(i, 2).Value2)s1 = Sheets.Item("current").Cells.Item(i, 2).Value2; else s1="";
if( Sheets.Item("current").Cells.Item(i, 3).Value2)s2 = Sheets.Item("current").Cells.Item(i, 3).Value2 ; else s2="";
if(s1 != "" && s2 == "") //有母本号
{
nameandhistory.name="";
nameandhistory.history="";
if(检索名称(s1, nameandhistory))
{
s2=nameandhistory.name;
//alert(" if(检索名称(s1, nameandhistory)) "+nameandhistory.name) ;
var length = s2.length;
if(s2.substr(length - 2,2)=="F1")
{
s3 = s2.substr(0, length - 2)+ "F2" ;//将F1 换成 F2
nameandhistory.name=s3;
//alert("f1name:"+f1name) ;
return true;
}
}
else return false;
}
}
function 杂交检索( mcode,NAME)
{//规定杂交种必须单独号段,在表格中也得与其它以空行隔开
var s1="";
for(var i=2;i<10000;i++)
{
//alert(Sheets.Item("current").Cells.Item(i, 1).Value2.toString());
s1= Sheets.Item("current").Cells.Item(i, 1).Value2;
NAME.value = "";
if(s1==mcode)
{
NAME.value=Sheets.Item("current").Cells.Item(i,4).Value2.toString();
if((typeof NAME.value)=="undefinded") NAME.value=Sheets.Item("current").Cells.Item(i,2).Value2.toString();
return true;
}
}
return false;
}
function 杂交计划生成程序()
//规定 2015.3.31 2022.12.12ok
{
var selfname={value:""};
for (var i=2 ;i<200;i++)
{
var code1 = Sheets.Item("cross").Cells.Item(i, 2).Value2;
var code2 = Sheets.Item("cross").Cells.Item(i, 3).Value2;
var code3 = Sheets.Item("cross").Cells.Item(i, 4).Value2;
var NAME = Sheets.Item("cross").Cells.Item(i, 5).Value2;
//alert("code1="+code1+" code2="+code2+" code3="+code3+" NAME="+NAME);
if ((typeof code1)!= "undefined" && (typeof code2)== "undefined")//亲本抄录
{
杂交检索(code1, selfname) ;
Sheets.Item("cross").Cells.Item(i, 3).Value2 = selfname.value;
Sheets.Item("cross").Cells.Item(i, 3).Activate;
}
if ((typeof code3)!= "undefined" && (typeof NAME)== "undefined")//亲本抄录
{
杂交检索(code3, selfname);
Sheets.Item("cross").Cells.Item(i, 5).Value2 = selfname.value;
Sheets.Item("cross").Cells.Item(i, 5).Activate;
}
}
}
function SplitMotherAndFather(father,sonMother,sonFather)
{
var LocCross , LocF , LocBC;
var lenth=father.length ;
var nLeftBraket , nRightBraket;
var i ;
LocCross = 0;
LocF = 0;
LocBC = 0;
nLeftBraket = 0;
nRightBraket = 0;
for(var i=lenth-1 ;i>0;i--)
{
if(father.substr(i,1)==")" && father.substr(i+1,1)=="F")
{
LocF = i;
break;
}
}
for(var i=lenth-2 ;i>0;i--)
{
if(father.substr(i,1)==")" && father.substr(i+1,2)=="BC")
{
LocBC = i;
break;
}
}
if( LocF>0)
{
for(var i=LocF-1;i>=2;i--)
{
if(father.substr(i,1) == ")" ) nRightBraket = nRightBraket + 1;
if(father.substr(i,1) == "(" ) nLeftBraket = nLeftBraket + 1;
if ((nRightBraket - nLeftBraket) == 0 )
{
if(father.substr(i,1) == "/" )
{
LocCross = i;
//alert("LocCross="+LocCross);
sonMother.value = father.substr(1, LocCross -1);
sonFather.value = father.substr( LocCross + 1, LocF - LocCross - 1);
break;
}
}
}
}
else if (LocBC != 0)
{
for(var i=LocBC-1;i>=2;i--)
{
if(father.substr(i,1) == ")" ) nRightBraket = nRightBraket + 1;
if(father.substr(i,1) == "(" ) nLeftBraket = nLeftBraket + 1;
if ((nRightBraket - nLeftBraket) == 0 )
{
if(father.substr(i,1) == "/" )
{
LocCross = i;
//alert("LocCross="+LocCross);
sonMother.value = father.substr(1, LocCross - 1);
sonFather.value = father.substr( LocCross + 1, LocBC - LocCross - 1);
break;
}
}
}
}
return LocCross;
}
function 回交种系谱编制(i,bcname)
{
var j,lenth, LocBC, LocF, N, lenbc;
var s1, s2, s3, s;
var sbc, sf, sbc = ")BC", sf = ")F";
var msonFather={value:""}, msonMother={value:""}; //未起用历史记录
var fsonFather={value:""}, fsonMother={value:""};
if(Sheets.Item("current").Cells.Item(i, 2).Value2)s1 = Sheets.Item("current").Cells.Item(i, 2).Value2;else s1="";
if( Sheets.Item("current").Cells.Item(i, 3).Value2)s2 = Sheets.Item("current").Cells.Item(i, 3).Value2;else s2="";
var mother={name:"",history:""};
var father={name:"",history:""};
检索名称 (s1, mother);
检索名称 (s2, father);
SplitMotherAndFather(father.name, fsonMother, fsonFather);
var isBC = SplitMotherAndFather(mother.name, msonMother, msonFather);
//alert(isBC);
if(mother.name !="" && father.name !="")
{//有双亲号
if ((mother.name.indexOf(fsonFather.value)>= 0 && fsonFather.value != "") ||
(mother.name.indexOf(fsonMother.value) >=0 && fsonMother.value !=""))
{//
if (father.name.indexOf(sbc) >= 0)
{
LocBC = father.name.indexOf(sbc);
lenth = father.name.length;
s3 = father.name.substr( LocBC + 1,10);
sf = "F";
LocF = s3.indexOf( sf);
lenbc = s3.length;
s =s3.substr(2, LocF - 2);
N = Number(s) + 1;
//alert("1 s="+s+" N="+N);
bcname.value = "(" + fsonMother.value + "/" + fsonFather.value + ")" + "BC" + N +"F1"; //新的字串
return true;
//Sheets.Item("current").Cells.Item(i, 6).Activate
}
else
{
s = "("+ fsonMother.value + "/" + fsonFather.value + ")";
bcname.value = s + " BC1F1" ;//2020.2.29 ok
return true;
}
}
if ((father.name.indexOf(msonFather.value) >= 0 && msonFather.value != "")
|| (father.name.indexOf( msonMother.value) >= 0 && msonMother.value != ""))
{//ok
if (mother.name.indexOf(sbc) >= 0 )
{
LocBC = mother.name.indexOf( sbc);
lenth = mother.name.lengh;
s3 = mother.name.substr( LocBC + 1,10);
// alert("s3="+s3);
sf = "F";
LocF =s3.indexOf( sf);
lenbc = s3.length;
s = s3.substr( 2,LocF-2);
//alert("s="+s);
N = Number(s) + 1;
//alert("2 s="+s+" N="+N);
bcname.value = "(" + msonMother.value + "/" + msonFather.value + ")" + "BC" + N + "F1"; //新的字串
return true;
//Sheets.Item("current").Cells.Item(i, 6).Activate
}
else
{
s = "(" + msonMother.value + "/" + msonFather.value + ")"
bcname.value = s + " BC1F1" //2020.2.29 ok
return true;
}
}
}
//新加内容201606
if (father.name.indexOf(msonFather.value) >= 0 && msonFather.value !="") //保持系选种回交型
{
//MsgBox "保持系选种回交型=" + father
if (mother.name.indexOf(sbc) >= 0 )
{
LocBC = mother.name.indexOf( sbc);
lenth = mother.name.length;
s3 = mother.substr(LocBC + 1,10);
lenbc = s3.length;
sf = "F";
LocF = InStr(s3, sf)
s = s3.substr(2, LocF - 2);
N = Number(s)+ 1;
//alert("3 s="+s+" N="+N);
bcname = "(" + msonMother.value + "/" + father.name + sbc + N + "F1" //新的字串
return true;
Sheets.Item("current").Cells.Item(i, 6).Activate
}
else
{
lenth = mother.name.length;
sf = "F";
LocF = mother.name.indexOf(sf);
sbc = "(" + msonMother.value + "/" + father.name + ")"
bcname = sbc + " BC1F1" //2013.4.18 ADD
return true;
}
}
return false;
}
function 杂交衍生(mcode ,fcode , crossname)// 2013.03.18
{
//规定杂交种必须单独号段,在表格中也得与其它以空行隔开
var s1, s2 , s3 ;
var code;
s2 = ""; s3 = "";
for(var i=2 ;i<10000;i++)
{
if(Sheets.Item("last").Cells.Item(i, 1).Value2)s1 = Sheets.Item("last").Cells.Item(i, 1).Value2;else s1="";
if( s1 == mcode)//搜索到则返回相应数值并返回成功标志
{
s2 = Sheets.Item("last").Cells.Item(i, 4).Value2;
//alert(s2);
break;
}
}
for(var i=2 ;i<10000;i++)
{
if(Sheets.Item("last").Cells.Item(i, 1).Value2)s1 = Sheets.Item("last").Cells.Item(i, 1).Value2;else s1="";
if( s1 == fcode)//搜索到则返回相应数值并返回成功标志
{
s3 = Sheets.Item("last").Cells.Item(i, 4).Value2;
//alert(s3);
break;
}
}
if (s2.indexOf( "/")> 0 && s2.indexOf( "(") !=0 ) s2 = "(" + s2 + ")" //2013.4.18 add
if (s3.indexOf("/")> 0 && s3.indexOf( "(") != 0 ) s3 = "(" + s3 + ")" //2013.4.18 add
if (s2 != "" && s3 != "" )
{
crossname.value = "(" + s2 + "/" + s3 + ")F1"; //标准方法
return true;//成功处理返回true
}
else if (s2 != "" && s3 == "" )
{
crossname.value = "(" & s2 + "/" + fcode + ")F1" ;//非标准方法
return true;//成功处理返回true
}
else if (s2 == "" && s3 != "")
{
crossname.value = "(" + mcode + "/" + s3 + ")F1" ;//非标准方法
return true;//成功处理返回true
}
else if (mcode != "" && fcode != "")
{
crossname.value = "(" + mcode + "/" + fcode + ")F1" ;//非标准方法
return true;//成功处理返回true
}
else return false;//失败
}
//规定 2013.3.31
//亲本以P开头****
//高代测交参与系谱编号****
//小区比较全部以字母分组****
//同一类编码必须码长相等****
//杂交种名称、编号表示方式相兼容****
//回交种以修改BCmFn为准****
// 混合选择以“#”标记于父本号内
// 定型材料可以“@”标记于父本号内
function 种质名称生成程序()
{
//重点改写 要对同母本号的株系进行统计并分别计数编号,已经统计者于父本号内标“已编系谱”
var s1, s2, s3, bcname={value:""}, crossname={value:""}, selfname={value:""}, f1name={value:""};
var code1, code2, code3, NAME;
var condition=false ;
var nameandhistory={name:"",history:""};
//要防止成对杂交选系进入系谱编码
for(var i=2;i<5000;i++)
{
if(Sheets.Item("current").Cells.Item(i, 1).Value2) code1 = Sheets.Item("current").Cells.Item(i, 1).Value2;else code1="";
if(Sheets.Item("current").Cells.Item(i, 2).Value2) code2 = Sheets.Item("current").Cells.Item(i, 2).Value2;else code2="";
if(Sheets.Item("current").Cells.Item(i, 3).Value2) code3 = Sheets.Item("current").Cells.Item(i, 3).Value2;else code3="";
if(Sheets.Item("current").Cells.Item(i, 4).Value2) NAME = Sheets.Item("current").Cells.Item(i, 4).Value2;else NAME="";
console.log(i);console.log(" code1= "+code1+" code2= "+code2+" code3= "+code3+" NAME= "+NAME);
if(( code1)!="" && ( code2)!="" &&( NAME)=="" )
{// 跳出空记录及无上季记录的记录行
if(code1 !="" && code2 !="" && code3 =="" )
{
var code1num=code1.charCodeAt(2);
var code2num=code2.charCodeAt(2);
//alert("code1num="+code1num);alert(" code2num="+code2num);
//if (code1num>=48 && code1num<=57 && code2num>=48 && code2num<=57 && code3 != "@" && (typeof NAME) == "undefined")
if (code1num>=48 && code1num<=57 && code2num>=48 && code2num<=57)
condition = true;
else condition=false;
//console.log(condition);
}
//alert(condition + " "+ i) ;
if( code2 !="" && code3 !="" && code3!="#" && code3!="@" )
{
//只将0001-9999编号作为杂交种2013.3.28
//调用杂交程序
if (回交种系谱编制(i, bcname))
{
Sheets.Item("current").Cells.Item(i, 4).Value2 = bcname.value;
//console.log(" 回交种系谱编制 "+bcname.value);
}
else
{
if (杂交衍生(code2, code3, crossname) ) Sheets.Item("current").Cells.Item(i, 4).Value2 = crossname.value;
//console.log(" 杂交衍生 "+crossname.value);
}
}
else if(杂交种加代(i, nameandhistory) )
{
Sheets.Item("current").Cells.Item(i, 4).Value2 = nameandhistory.name;
Sheets.Item("current").Cells.Item(i, 6).Value2 = nameandhistory.history;
//console.log("杂交种加代"+nameandhistory.name);
}
else if( code2 !="" && code3 == "@" )//亲本抄录
{
检索名称 (code2, nameandhistory);
Sheets.Item("current").Cells.Item(i, 4).Value2 = nameandhistory.name;
Sheets.Item("current").Cells.Item(i, 6).Value2 = nameandhistory.history
//console.log(" 亲本抄录 "+nameandhistory.name);
}
else if( code2 !="" && code3 =="#" )//混合选择
{
检索名称 (code2, nameandhistory);
Sheets.Item("current").Cells.Item(i, 4).Value2 = nameandhistory.name +"-0";
Sheets.Item("current").Cells.Item(i, 6).Value2 = nameandhistory.history;
//console.log(" 混合选择 "+nameandhistory.name);
}
else if( code1 !="" && code2!="" && condition )
{//调用自交衍生程序
if(检索名称 (code2, nameandhistory)) 自交衍生编号 (code2,nameandhistory);
//console.log("调用自交衍生程序 "+nameandhistory.name);
}
else if( code2 !="" && code3 =="")
{
//调用抄录程序
if(检索名称 (code2, nameandhistory))
{
Sheets.Item("current").Cells.Item(i, 4).Value2 = nameandhistory.name
Sheets.Item("current").Cells.Item(i, 6).Value2 = nameandhistory.history
//console.log("调用抄录程序 "+nameandhistory.name);
}
}
}
Sheets.Item("current").Cells.Item(i, 4).Activate;
}
}
function 自交衍生编号(mcode,nameandhistory)
{//2022.12.12 ok by chentingmu
//仅作单个母本号检索用,以简化程序结构
//重点改写 要对同母本号的株系进行统计并分别计数编号,已经统计者于父本号内标“已编系谱”
//要防止成对杂交选系进入系谱编码
var N =0;
var record=[]; //前者记录系谱,后者记录记录号,n记录同源材料总数
N = 0
for(var i=2;i<5000;i++)
{
if(Sheets.Item("current").Cells.Item(i, 1).Value2)var code1 = Sheets.Item("current").Cells.Item(i, 1).Value2;else var code1="";//辅助判断是否自交种衍生
if(Sheets.Item("current").Cells.Item(i, 2).Value2)var code2 = Sheets.Item("current").Cells.Item(i, 2).Value2;else var code2="";
if(Sheets.Item("current").Cells.Item(i, 3).Value2)var code3 = Sheets.Item("current").Cells.Item(i, 3).Value2; else var code3="";
if(Sheets.Item("current").Cells.Item(i, 4).Value2)var code4 = Sheets.Item("current").Cells.Item(i, 4).Value2;else var code4="";
//单株选择编号, 上季与本季均为选种编号
if( code1 != "" && ( code2)!= "")//if("undefined" == typeof myVar01)
{
var code1num=code1.toString().charCodeAt(2);
var code2num=code2.toString().charCodeAt(2);
if (code1num>=48 && code1num<=57 && ( code4) == "")//只将0001-9999编号作为选种2013.3.28 && code3 != "@" && (typeof code4) != "string"
{
//console.log("code1="+ code1num+" code2="+ code2num +" " +code2 +" mcode "+mcode );
if(code2 == mcode && ( code3)=="" )// 仅有母本号,且未做标记
{
record[N] = i;
N = N + 1;
// console.log("N="+N+" code1="+ code1num+" code2="+ code2num );
}
}
}
}
检索名称 (mcode, nameandhistory);
/*大写字母A 到Z 的值是从65 到90 小写a到z 是从91 到 122 字符转ascii码:用charCodeAt(); ascii码砖字符:用fromCharCode();*/
for(var i = 0 ;i< N ;i++)//编号
{
//alert(Sheets.Item("current").Cells.Item(record[i], 4));
//console.log("i="+i+" record="+ record[i] );
Sheets.Item("current").Cells.Item(Number(record[i]), 4).Value2 = nameandhistory.name + "-" + (i+1);
Sheets.Item("current").Cells.Item(Number(record[i]), 6).Value2 = nameandhistory.history;
Sheets.Item("current").Cells.Item(Number(record[i]), 4).Activate;
}
}
function 检索名称(mcode, nameandhistory) // 2013.03.18
//仅作单个母本号检索用,以简化程序结构
{
//规定杂交种必须单独号段,在表格中也得与其它以空行隔开
var s1="";
for(var i=2;i<5000;i++)
{
if(Sheets.Item("last").Cells.Item(i, 1).Value2) s1 = Sheets.Item("last").Cells.Item(i,1).Value2;else s1="";
//console.log("i="+i+" s1="+ s1+" mcode="+mcode );
if (s1 == mcode)//搜索到则返回相应数值并返回成功标志
{
//alert("检索名称"+s1) ;
nameandhistory.name = Sheets.Item("last").Cells.Item(i, 4).Value2 ;
if (Sheets.Item("last").Cells.Item(i, 5).Value2)
{
if(Sheets.Item("last").Cells.Item(i, 6).Value2)var a=Sheets.Item("last").Cells.Item(i, 6).Value2;else var a="";
if(a!="") nameandhistory.history = Sheets.Item("last").Cells.Item(i, 6).Value2
+Sheets.Item("last").Cells.Item(i, 1).Value2.substring(0,2)+ ":"+ Sheets.Item("last").Cells.Item(i, 5).Value2;
else nameandhistory.history = Sheets.Item("last").Cells.Item(i, 1).Value2.toString().substring(0,2)+ ":"+ Sheets.Item("last").Cells.Item(i, 5).Value2;
}
else nameandhistory.history = Sheets.Item("last").Cells.Item(i, 6).Value2;
return true;
}
}
return false;
}
function Person(name)
{
this.name = name;
this.getName = function(){
return this.name;
}
}
function tryjs() //我们在这里实例化几个对象
{
var p1 = new Person("trigkit4");
var p2 = new Person("mike");
console.log(p1.name);//true
console.log(p2.name);//true
}