private void LoadPlantcode()
 {
     try
     {
         SqlDataReader dr = null;
         ddl_Plantcode.Items.Clear();
         ddl_Plantname.Items.Clear();
         dr = Bllusers.LoadPlantcode(ccode.ToString());
         if (dr.HasRows)
         {
             while (dr.Read())
             {
                 ddl_Plantcode.Items.Add(dr["Plant_Code"].ToString());
                 ddl_Plantname.Items.Add(dr["Plant_Code"].ToString() + "_" + dr["Plant_Name"].ToString());
             }
         }
         else
         {
             ddl_Plantcode.Items.Add("--Select PlantName--");
             ddl_Plantname.Items.Add("--Select Plantcode--");
         }
     }
     catch (Exception EE)
     {
         string message;
         message = EE.ToString();
         string script = "window.onload = function(){ alert('";
         script += message;
         script += "')};";
         ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
     }
 }
 protected void Button5_Click(object sender, EventArgs e)
 {
     try
     {
         getgridviewrows();
     }
     catch (Exception EE)
     {
         string message;
         message = EE.ToString();
         string script = "window.onload = function(){ alert('";
         script += message;
         script += "')};";
         ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
     }
 }
示例#3
0
        //打包主流程
        private void copyDecompileFile(string game, string channel, ProgressBar pro, Label lb)
        {
            // 拷贝游戏
            copyFolder(fromPath, envConfig.targetPath + @game + @"\" + channel + @"\", pro, lb, game);

            // 保存参数文件--assets
            string propertiesFile = envConfig.gameConfig + game + @"\" + channel + envConfig.configExt;

            if (!Directory.Exists(envConfig.targetPath + @game + @"\" + channel + @"\assets\"))
            {
                Directory.CreateDirectory(envConfig.targetPath + @game + @"\" + channel + @"\assets\");
            }
            if (getNum == fileNum)
            {
                File.Copy(propertiesFile, envConfig.targetPath + @game + @"\" + channel + @"\assets\" + game + envConfig.configExt, true);
                curEvent.Text = "copy  " + channel + "  完成.";
                pbT.Value     = 20;
            }
            //合并文件
            string apkBase = envConfig.channelPath + channel + @"\apkBase\";

            if (!Directory.Exists(apkBase))
            {
                MessageBox.Show("不存在sdk母包文件");
                return;
            }
            File.Delete(apkBase + @"AndroidManifest.xml");
            File.Delete(apkBase + @"apktool.yml");
            mergeFolder(envConfig.targetPath + @game + @"\" + channel + @"\", apkBase, pro, lb, channel);
            // propertiesFile = envConfig.gameConfig + game + @"\" + channel + envConfig.configExt;

            File.Copy(propertiesFile, envConfig.targetPath + @game + @"\" + channel + @"\assets\" + game + envConfig.configExt, true);
            //检测游戏母包是否还有其他文件操作
            delArmeabi(game, envConfig.targetPath + @game + @"\" + channel + @"\lib");
            fileNum = 0;
            //todo merge xml
            string gameXml = envConfig.targetPath + @game + @"\" + channel + @"\AndroidManifest.xml";
            string xxxPath = envConfig.targetPath + @game + @"\" + channel + @"\res\drawable-xxxhdpi\";

            if (Directory.Exists(xxxPath))
            {
                FileUtil.deleteFolder(xxxPath);
            }
            curEvent.Text = "合并" + gameXml;
            this.mergeXml(gameXml, channel);
            curEvent.Text = "xml合并完成";

            pro.Value = 60;
            pbT.Value = 60;
            lb.Text   = "60%";

            //todo replace packageName
            string   oldName     = getPackName(gameXml);
            PpHelper pt          = new PpHelper(propertiesFile);
            string   packageName = pt.GetPropertiesText("package");

            this.replaceSpecGameXml(game, gameXml, packageName, oldName);
            //todo 特殊游戏包名
            if (packageName.Length > 0)
            {
                XmlHelper.XmlAttributeEdit(gameXml, "manifest", "package", packageName);
            }
            string tmpXml1     = FileUtil.setXmlColon(FileUtil.getContent(gameXml));
            string xmlTmpFile1 = gameXml + @".tmp";

            FileUtil.writeContent(xmlTmpFile1, tmpXml1);
            XmlDocument dDoc = new XmlDocument();

            dDoc.Load(xmlTmpFile1);
            XmlNode    dpath = dDoc.SelectSingleNode(@"//manifest/application");
            XmlElement dXe   = (XmlElement)dpath;

            //    dXe.GetAttribute("android" + FileUtil.colon + "debuggable");
            dXe.SetAttribute("android" + FileUtil.colon + "debuggable", "false");
            dDoc.Save(xmlTmpFile1);
            tmpXml1 = FileUtil.replaceXmlColon(FileUtil.getContent(xmlTmpFile1));
            tmpXml1 = FileUtil.xmlRestore(tmpXml1);
            FileUtil.writeContent(gameXml, tmpXml1);
            File.Delete(xmlTmpFile1);



            //  string tmpXml = FileUtil.setXmlColon(FileUtil.getContent(gameXml));
            pbT.Value     = 61;
            pro.Value     = 61;
            lb.Text       = "61%";
            curEvent.Text = "包名替换完成";

            //todo copy ico
            if (picString.Length > 0)
            {
                string tmpXml     = FileUtil.setXmlColon(FileUtil.getContent(gameXml));
                string xmlTmpFile = gameXml + @".tmp";
                FileUtil.writeContent(xmlTmpFile, tmpXml);
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(xmlTmpFile);
                XmlNode    basePath = xmlDoc.SelectSingleNode(@"//manifest/application");
                XmlElement baseXe   = (XmlElement)basePath;
                string     icoName  = baseXe.GetAttribute("android" + FileUtil.colon + "icon");
                icoName = icoName.Substring(icoName.IndexOf('/') + 1);
                copyIco(picString, envConfig.targetPath + @game + @"\" + channel + @"\res\", icoName + ".png", channel);
                tmpXml = FileUtil.replaceXmlColon(FileUtil.getContent(xmlTmpFile));
                tmpXml = FileUtil.xmlRestore(tmpXml);
                FileUtil.writeContent(gameXml, tmpXml);
                File.Delete(xmlTmpFile);
            }

            //todo 检测渠道XML是否有特殊操作
            try
            {
                updateChannelXml(game, channel, gameXml, propertiesFile);
            }
            catch (Exception EE)
            {
                MessageBox.Show(EE.ToString());
            }
            curEvent.Text = "特殊渠道xml处理完成";

            //todo merge res *.xml

            this.mergeRes(channel, game);
            pbT.Value     = 65;
            pro.Value     = 65;
            lb.Text       = "65%";
            curEvent.Text = "res xml 合并完成";
            //todo make R.java
            //todo compile class file
            //todo make dex
            //todo make smali
            //todo merge smali
            string targetPath = envConfig.targetPath + game + @"\" + channel + @"\";
            string resPath    = targetPath + "res";
            string tmpFolder  = envConfig.upPath + @"temp\";
            string tmpCls     = tmpFolder + @"class\";
            string tmpR       = tmpFolder + @"R\";

            if (Directory.Exists(tmpR))
            {
                FileUtil.deleteFolder(tmpR);
            }
            Directory.CreateDirectory(tmpR);
            if (Directory.Exists(tmpCls))
            {
                FileUtil.deleteFolder(tmpCls);
            }
            Directory.CreateDirectory(tmpCls);
            string packagePath  = packageName.Replace(".", @"\");
            string javaFilePath = tmpR + packagePath;

            //            MessageBox.Show("java file:"+javaFilePath);
            curEvent.Text = "开始生成R文件";
            Process makeR = new Process();

            if (this.isDebug() == false)
            {
                makeR.StartInfo.UseShellExecute        = false;
                makeR.StartInfo.CreateNoWindow         = true;
                makeR.StartInfo.FileName               = envConfig.toolPath + @"\makeR.bat";
                makeR.StartInfo.RedirectStandardInput  = true;
                makeR.StartInfo.RedirectStandardOutput = true;
                makeR.StartInfo.RedirectStandardError  = true;
            }
            else
            {
                makeR.StartInfo.FileName = envConfig.toolPath + @"\makeR-debug.bat";
            }
            makeR.StartInfo.Arguments = " " + resPath + " " + targetPath + "AndroidManifest.xml" + " " + tmpR + "  " + tmpCls + " " + javaFilePath + " " + envConfig.targetPath + @game + @"\" + channel + @"\assets\";

            makeR.Start();
            string       line   = "\r\n";
            StreamReader reader = null;

            if (this.isDebug() == false)
            {
                reader = makeR.StandardOutput; //截取输出流
                line   = reader.ReadLine();    //每次读取一行
                while (!reader.EndOfStream)
                {
                    line  = reader.ReadLine();
                    line += "\r\n" + line;
                    richTxtInfo.AppendText(line);
                    richTxtInfo.SelectionStart = richTxtInfo.Text.Length;
                    richTxtInfo.ScrollToCaret();
                }
            }
            makeR.WaitForExit();
            pbT.Value     = 70;
            pro.Value     = 70;
            lb.Text       = "70%";
            curEvent.Text = "R文件生成完成";
            richTxtInfo.AppendText("\r\n R文件生成完成\r\n");



            if (makeRYes.Checked == true)
            {
                string channelXml    = envConfig.channelPath + channel + @"\channel.xml";
                string chanelPackage = XmlHelper.getChannelAtrr(channelXml, "chanelPackage");
                MessageBox.Show(chanelPackage);
                makeChannelRes(channel, pro, lb);
            }

            curEvent.Text = "生成class文件";
            Process makeDex = new Process();

            if (this.isDebug() == false)
            {
                makeDex.StartInfo.UseShellExecute        = false;
                makeDex.StartInfo.CreateNoWindow         = true;
                makeDex.StartInfo.FileName               = envConfig.toolPath + @"\dx.bat";
                makeDex.StartInfo.RedirectStandardInput  = true;
                makeDex.StartInfo.RedirectStandardOutput = true;
                makeDex.StartInfo.RedirectStandardError  = true;
            }
            else
            {
                makeDex.StartInfo.FileName = envConfig.toolPath + @"\dx.bat";
            }
            makeDex.StartInfo.Arguments = "   --dex --output=" + tmpFolder + "temp.dex  " + tmpCls;

            makeDex.Start();
            line = "\r\n";
            if (this.isDebug() == false)
            {
                reader = makeDex.StandardOutput; //截取输出流
                line   = reader.ReadLine();      //每次读取一行
                while (!reader.EndOfStream)
                {
                    line  = reader.ReadLine();
                    line += "\r\n" + line;
                    richTxtInfo.AppendText(line);
                    richTxtInfo.SelectionStart = richTxtInfo.Text.Length;
                    richTxtInfo.ScrollToCaret();
                }
            }
            makeDex.WaitForExit();
            richTxtInfo.AppendText("\r\n  class文件生成完成\r\n");


            curEvent.Text = "生成smali";
            Process makeSmali = new Process();

            if (this.isDebug() == false)
            {
                makeSmali.StartInfo.UseShellExecute        = false;
                makeSmali.StartInfo.CreateNoWindow         = true;
                makeSmali.StartInfo.FileName               = envConfig.toolPath + @"\getSmali.bat";
                makeSmali.StartInfo.RedirectStandardInput  = true;
                makeSmali.StartInfo.RedirectStandardOutput = true;
                makeSmali.StartInfo.RedirectStandardError  = true;
            }
            else
            {
                makeSmali.StartInfo.FileName = envConfig.toolPath + @"\getSmali-debug.bat";
                MessageBox.Show("begin");
            }
            makeSmali.StartInfo.Arguments = targetPath + @"smali\   " + tmpFolder + "temp.dex  ";

            makeSmali.Start();
            line = "\r\n";
            if (this.isDebug() == false)
            {
                reader = makeSmali.StandardOutput; //截取输出流
                line   = reader.ReadLine();        //每次读取一行
                while (!reader.EndOfStream)
                {
                    line  = reader.ReadLine();
                    line += "\r\n" + line;
                    richTxtInfo.AppendText(line);
                    richTxtInfo.SelectionStart = richTxtInfo.Text.Length;
                    richTxtInfo.ScrollToCaret();
                }
            }
            makeSmali.WaitForExit();
            pbT.Value     = 75;
            pro.Value     = 75;
            lb.Text       = "75%";
            curEvent.Text = "smali  合并完成";
            richTxtInfo.AppendText("\r\n" + "smali  合并完成\r\n");
            FileUtil.deleteFolder(tmpR);
            FileUtil.deleteFolder(tmpCls);
            File.Delete(tmpFolder + "temp.dex");

            string packageFolder  = envConfig.targetPath + @game + @"\" + channel + @"\";
            string compileFolder  = envConfig.compileFolder + game + @"\";
            string mkTime         = DateTime.Now.ToString("yyyyMMddHHmmss");
            string compileApkName = channel + "_" + mkTime + ".apk";

            Process p = new Process();

            if (this.isDebug() == false)
            {
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.CreateNoWindow         = true;
                p.StartInfo.FileName               = envConfig.apkToolCommand;
                p.StartInfo.RedirectStandardInput  = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError  = true;
            }
            else
            {
                p.StartInfo.FileName = envConfig.currenPath + @"\apktool\apktool-debug.bat";
            }
            string compileApk = compileFolder + compileApkName;

            p.StartInfo.Arguments = "  b  " + packageFolder + "  -o  " + compileApk;

            p.Start();
            line = "\r\n";
            if (this.isDebug() == false)
            {
                reader = p.StandardOutput;  //截取输出流
                line   = reader.ReadLine(); //每次读取一行
                while (!reader.EndOfStream)
                {
                    line  = reader.ReadLine();
                    line += "\r\n" + line;
                    richTxtInfo.AppendText(line);
                    richTxtInfo.SelectionStart = richTxtInfo.Text.Length;
                    richTxtInfo.ScrollToCaret();
                }
            }
            p.WaitForExit();
            pbT.Value     = 80;
            pro.Value     = 80;
            lb.Text       = "80%";
            curEvent.Text = channel + " 打包完成";
            richTxtInfo.AppendText("\r\n" + curEvent.Text + "\r\n");

            Process makeSign = new Process();

            // 签名-调用命令行输出
            //makeSign.StartInfo.UseShellExecute = false;
            //makeSign.StartInfo.CreateNoWindow = true;
            //makeSign.StartInfo.RedirectStandardInput = true;
            //makeSign.StartInfo.RedirectStandardOutput = true;
            //makeSign.StartInfo.RedirectStandardError = true;


            string signPwd      = txtSignPwd.Text.ToString();
            string keyStrorePwd = txtKeyPwd.Text.ToString();
            string keyStore     = lbPwdFile.Text.ToString();
            string alias        = txtAlias.Text.ToString();
            string releasePath  = envConfig.releasePkg + game + @"\";

            if (!Directory.Exists(releasePath))
            {
                Directory.CreateDirectory(releasePath);
            }
            string releaseApk = releasePath + game + "_" + compileApkName;

            //  makeSign.StartInfo.FileName = envConfig.signPath + "jarsigner";
            makeSign.StartInfo.FileName = "jarsigner";
            //  compileApk = @"C:\Users\win8\Desktop\123.apk";
            makeSign.StartInfo.Arguments = "  -digestalg SHA1 -sigalg MD5withRSA -verbose -keystore " + keyStore + " -storepass " + keyStrorePwd + " -keypass " + signPwd + " -signedjar  " + releaseApk + "  " + compileApk + "  " + alias;


            Clipboard.SetText(makeSign.StartInfo.FileName + " " + makeSign.StartInfo.Arguments);
            //     MessageBox.Show("beginSign");

            makeSign.Start();

            //reader = makeSign.StandardOutput;//截取输出流
            //line = "\r\n";
            //line = reader.ReadLine();//每次读取一行
            //while (!reader.EndOfStream)
            //{
            //    line = reader.ReadLine();
            //    line += "\r\n" + line;
            //    richTxtInfo.AppendText(line);
            //    richTxtInfo.SelectionStart = richTxtInfo.Text.Length;
            //    richTxtInfo.ScrollToCaret();
            //}

            makeSign.WaitForExit();

            pbT.Value     = 100;
            pro.Value     = 100;
            lb.Text       = "100%";
            curEvent.Text = channel + "签名完成";
            richTxtInfo.AppendText("\r\n" + curEvent.Text + "\r\n");


            //todo 加固
        }
示例#4
0
    protected void Button5_Click(object sender, EventArgs e)
    {
        checkcodition();

        if (datacheck == 0)
        {
            gettingprocurementimportdata();
            foreach (DataRow importprodata in DTG.Tables[0].Rows)
            {
                Getagentid = importprodata[1].ToString();
                //   prdate = importprodata[2].ToString();
                string   Convedate = importprodata[2].ToString();
                string[] arrdate   = Convedate.Split('-');

                string dd = arrdate[0];
                string MM = arrdate[1];
                string yy = arrdate[2];

                prdate    = MM + "/" + dd + "/" + yy;
                GET       = prdate.Split(' ');
                prdate    = GET[0].ToString();
                Sessions  = importprodata[3].ToString();
                FAT       = Convert.ToDouble(importprodata[5]);
                SNF       = Convert.ToDouble(importprodata[6]);
                PlantCode = importprodata[7].ToString();
                Route_id  = importprodata[8].ToString();
                NoofCans  = Convert.ToInt16(importprodata[9]);
                Milk_kg   = Convert.ToDouble(importprodata[4]);
                string tempkg = Milk_kg.ToString("f2");
                Milk_kg  = Convert.ToDouble(tempkg);
                tmilkltr = (Milk_kg / 1.03).ToString("f2");
                milkltr  = Convert.ToDouble(tmilkltr);
                if (Milk_kg < 0)
                {
                    Milk_kg = 0;
                    milkltr = 0;
                }

                //   @Clr=(((@Snf - 0.36) - (@Fat * 0.21)) * 4)
                Clr  = Convert.ToDouble((((SNF - 0.36) - (FAT * 0.21)) * 4));
                tclr = Clr.ToString("f2");
                Clr  = Convert.ToDouble(tclr);
                // Clr = importprodata[11].ToString();
                Company_Code = importprodata[12].ToString();
                Milk_Nature  = importprodata[13].ToString();
                if (Milk_Nature == "1")
                {
                    MilkNature = "Cow";
                }
                else
                {
                    MilkNature = "Buffalo";
                }
                SampleId                = importprodata[14].ToString();
                Sampleno                = importprodata[15].ToString();
                milk_tip_st_time        = importprodata[16].ToString();
                milk_tip_end_time       = importprodata[17].ToString();
                usr_weigher             = importprodata[18].ToString();
                usr_analizer            = importprodata[19].ToString();
                fat_kg                  = ((Milk_kg / 100) * FAT).ToString("f2");
                snf_kg                  = ((Milk_kg / 100) * SNF).ToString("f2");
                Truck_id                = importprodata[22].ToString();
                Status                  = importprodata[23].ToString();
                ViewState["Getagentid"] = Getagentid.ToString();
                ViewState["FAT"]        = FAT.ToString();
                ViewState["SNF"]        = SNF.ToString();
                getroutedetails();
                if (countroute == 1)
                {
                }
                else
                {
                    string insertroute;
                    con         = DB.GetConnection();
                    insertroute = "INSERT INTO route_Master(route_Id,route_Name,tot_Distance,added_date,status,Company_Code,Plant_Code,Lstatus) values   ('" + Route_id + "' ,'" + "ROUTE-" + Route_id + "','" + 1 + "','" + System.DateTime.Now + "','" + 1 + "','" + ccode + "' ,'" + pcode + "','" + 1 + "')";
                    SqlCommand cmd = new SqlCommand(insertroute, con);
                }
                getagentdetails();
                if (countagent == 1)
                {
                }
                else
                {
                    string insertagnet;
                    con         = DB.GetConnection();
                    insertagnet = " INSERT INTO Agent_Master(Agent_Id,Agent_Name,Type,Cartage_Amt,Company_code,Plant_code,Route_id,Bank_Id,Payment_mode,Agent_AccountNo,AddedDate,phone_Number,Milk_Nature,Ifsc_code,SplBonus_Amt,agentratechartmode) values ('" + Getagentid + "','" + Getagentid + "','" + 0 + "','" + 0 + "','" + ccode + "','" + pcode + "','" + Route_id + "','" + 0 + "','CASH','" + 0 + "','" + 0 + "','" + Milk_Nature + "','" + 0 + "','" + 0 + ",'" + 0 + "')";
                    SqlCommand cmd = new SqlCommand(insertagnet, con);
                }
                gettingdatafromagentmaster();
                COUNTI = COUNTI + 1;
                foreach (DataRow agentmaster in DTG.Tables[COUNTI].Rows)
                {
                    cart     = Convert.ToDouble(agentmaster[0]);
                    nature   = agentmaster[1].ToString();
                    splbonus = Convert.ToDouble(agentmaster[2]);
                    //int agentchartmode  = Convert.ToInt16(agentmaster[3]);
                    //int dpuagent;
                    //try
                    //{
                    //  //  dpuagent = Convert.ToInt16(agentmaster[4]);
                    //}
                    //catch
                    //{
                    //     dpuagent = 0;

                    //}
                    cchartname                 = (agentmaster[5]).ToString(); //going to add filed chartname
                    bchartname                 = (agentmaster[6]).ToString();
                    ViewState["cart"]          = cart;
                    ViewState["spbonus"]       = splbonus;
                    ViewState["nature"]        = nature;
                    ViewState["cowchartname"]  = cchartname.ToString();
                    ViewState["buffchartname"] = bchartname.ToString();
                }

                if ((MilkNature == "1") || (MilkNature == "Cow"))
                {
                    gettingchartmaster();
                }

                else
                {
                    gettingchartmasterforbuff();
                }

                charttype = DTG.Tables[COUNTI].Rows[rows][1].ToString();
                minfat    = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][2]);
                maxfat    = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][3]);
                if ((MilkNature == "1") || (MilkNature == "Cow"))
                {
                    bufftocowrate = 0;
                    SnfCutting    = 0;
                }
                else
                {
                    bufftocowrate = Convert.ToDouble(DTG.Tables[COUNTI].Rows[1][4]);
                    SnfCutting    = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][5]);
                }
                NATURE = ViewState["nature"].ToString();

                if (NATURE == "Cow")
                {
                    if (charttype == "TS")
                    {
                        gettingTSratechart();

                        try
                        {
                            COUNTI     = COUNTI + 1;
                            RATE       = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][0]);
                            commission = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][1]);
                            bonus      = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][2]);
                            RATE       = RATE * (FAT + SNF);
                            RATEE      = RATE.ToString("F2");
                            RATE       = Convert.ToDouble(RATEE);
                            tempamount = (RATE * milkltr).ToString("F2");
                            if (RATE > 0)
                            {
                                amount = Convert.ToDouble(tempamount);
                            }
                            else
                            {
                                amount = 0;
                            }
                        }
                        catch (Exception EE)
                        {
                            string GET45 = EE.ToString();
                        }
                    }
                    if (charttype == "SNF")
                    {
                        COUNTI = COUNTI + 1;
                        gettingSNFratechart();
                        double TEMPRATE = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][0]);
                        commission = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][1]);
                        bonus      = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][2]);
                        double TEMPFAT = Convert.ToDouble(ViewState["FAT"]);
                        double TEMPSNF = Convert.ToDouble(ViewState["SNF"]);
                        RATE       = TEMPRATE * (TEMPFAT + TEMPSNF);
                        RATEE      = RATE.ToString("F2");
                        RATE       = Convert.ToDouble(RATEE);
                        tempamount = (RATE * milkltr).ToString("F2");


                        if (RATE > 0)
                        {
                            amount = Convert.ToDouble(tempamount);
                        }
                        else
                        {
                            amount = 0;
                        }
                    }
                    if (charttype == "FATSNF")
                    {
                        COUNTI = COUNTI + 1;
                        gettingFATSNFratechart();

                        commission = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][1]);
                        bonus      = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][2]);
                        double FRATE = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][0]);
                        gettingFATSNFratechartrate();
                        COUNTI = COUNTI + 1;
                        double SRATE       = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][0]);
                        double TEMPFATRATE = (FAT * FRATE);
                        double TEMPSNFRATE = (SNF * SRATE);
                        RATE       = (TEMPFATRATE + TEMPSNFRATE);
                        RATEE      = RATE.ToString("F2");
                        RATE       = Convert.ToDouble(RATEE);
                        tempamount = (RATE * milkltr).ToString("F2");

                        if (RATE > 0)
                        {
                            amount = Convert.ToDouble(tempamount);
                        }
                        else
                        {
                            amount = 0;
                        }
                    }
                    if (charttype == "FATSNFMIXED")
                    {
                        COUNTI = COUNTI + 1;
                        gettingFATSNFMIXINGFAT();
                        COUNTI = COUNTI + 1;
                        ViewState["FATSTATUS"] = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][0]);
                        gettingFATSNFMIXINGSNF();
                        COUNTI     = COUNTI + 1;
                        RATE       = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][0]);
                        commission = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][1]);
                        bonus      = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][2]);
                        commission = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][1]);
                        bonus      = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][2]);
                        double TEMPRATE = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][0]);
                        double TEMPFAT  = Convert.ToDouble(ViewState["FAT"]);
                        double TEMPSNF  = Convert.ToDouble(ViewState["SNF"]);
                        RATE       = TEMPRATE * (TEMPFAT + TEMPSNF);
                        tempamount = (RATE * milkltr).ToString("F2");
                        if (RATE > 0)
                        {
                            amount = Convert.ToDouble(tempamount);
                        }
                        else
                        {
                            amount = 0;
                        }
                    }
                    CHARTID = ViewState["cowchartname"].ToString();
                }
                if (NATURE == "Buffalo")
                {
                    if (charttype == "FAT")
                    {
                        COUNTI = COUNTI + 1;
                        gettingfatratechart();
                        RATE       = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][0]);
                        commission = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][1]);
                        bonus      = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][2]);
                        CHARTID    = ViewState["buffchartname"].ToString();

                        if (SnfCutting == 1)
                        {
                            snfcuttingplant();
                            COUNTI = COUNTI + 1;
                            double tempcut = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][5]);
                            RATE = RATE - tempcut;
                        }
                        else
                        {
                            RATE       = (FAT * RATE);
                            tempamount = (RATE * Milk_kg).ToString("F2");
                            amount     = Convert.ToDouble(tempamount);
                        }
                    }

                    if (FAT < bufftocowrate)
                    {
                        COUNTI = COUNTI + 1;



                        gettingdatafromagentmasterBUFFTOCOW();

                        foreach (DataRow agentmaster in DTG.Tables[COUNTI].Rows)
                        {
                            cart     = Convert.ToDouble(agentmaster[0]);
                            nature   = agentmaster[1].ToString();
                            splbonus = Convert.ToDouble(agentmaster[2]);
                            //int agentchartmode  = Convert.ToInt16(agentmaster[3]);
                            //int dpuagent;
                            //try
                            //{
                            //  //  dpuagent = Convert.ToInt16(agentmaster[4]);
                            //}
                            //catch
                            //{
                            //     dpuagent = 0;

                            //}
                            cchartname                 = (agentmaster[5]).ToString(); //going to add filed chartname
                            bchartname                 = (agentmaster[6]).ToString();
                            ViewState["cart"]          = cart;
                            ViewState["spbonus"]       = splbonus;
                            ViewState["nature"]        = nature;
                            ViewState["cowchartname"]  = cchartname.ToString();
                            ViewState["buffchartname"] = bchartname.ToString();
                        }


                        gettingchartmasterBUFFTOCOW();

                        charttype = DTG.Tables[COUNTI].Rows[0][1].ToString();
                        minfat    = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][2]);
                        maxfat    = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][3]);
                        NATURE    = ViewState["nature"].ToString();


                        if (charttype == "TS")
                        {
                            gettingTSratechartCOWBUFF();
                            COUNTI     = COUNTI + 1;
                            RATE       = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][0]);
                            commission = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][1]);
                            bonus      = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][2]);
                            RATE       = RATE * (FAT + SNF);
                            RATEE      = RATE.ToString("F2");
                            RATE       = Convert.ToDouble(RATEE);
                            tempamount = (RATE * Milk_kg).ToString("F2");
                            amount     = Convert.ToDouble(tempamount);
                        }
                        if (charttype == "SNF")
                        {
                            COUNTI = COUNTI + 1;
                            gettingSNFratechart();
                            double TEMPRATE = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][0]);
                            commission = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][1]);
                            bonus      = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][2]);
                            double TEMPFAT = Convert.ToDouble(ViewState["FAT"]);
                            double TEMPSNF = Convert.ToDouble(ViewState["SNF"]);
                            RATE       = TEMPRATE * (TEMPFAT + TEMPSNF);
                            RATEE      = RATE.ToString("F2");
                            RATE       = Convert.ToDouble(RATEE);
                            tempamount = (RATE * Milk_kg).ToString("F2");
                            amount     = Convert.ToDouble(tempamount);
                        }
                        if (charttype == "FATSNF")
                        {
                            COUNTI = COUNTI + 1;
                            gettingFATSNFratechart();
                            gettingFATSNFratechartrate();
                            commission = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][1]);
                            bonus      = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][2]);
                            double FRATE = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][0]);
                            COUNTI = COUNTI + 1;
                            double SRATE = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][0]);

                            double TEMPFATRATE = (FAT * FRATE);
                            double TEMPSNFRATE = (SNF * SRATE);
                            RATE       = (TEMPFATRATE + TEMPSNFRATE);
                            RATEE      = RATE.ToString("F2");
                            RATE       = Convert.ToDouble(RATEE);
                            tempamount = (RATE * Milk_kg).ToString("F2");
                            amount     = Convert.ToDouble(tempamount);
                        }
                        if (charttype == "FATSNFMIXED")
                        {
                            COUNTI = COUNTI + 1;
                            gettingFATSNFMIXINGFAT();
                            ViewState["FATSTATUS"] = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][0]);
                            gettingFATSNFMIXINGSNF();
                            COUNTI     = COUNTI + 1;
                            RATE       = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][0]);
                            commission = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][1]);
                            bonus      = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][2]);
                            commission = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][1]);
                            bonus      = Convert.ToDouble(DTG.Tables[COUNTI].Rows[rows][2]);
                            double TEMPRATE = Convert.ToDouble(DTG.Tables[COUNTI].Rows[0][0]);
                            double TEMPFAT  = Convert.ToDouble(ViewState["FAT"]);
                            double TEMPSNF  = Convert.ToDouble(ViewState["SNF"]);
                            RATE       = TEMPRATE * (TEMPFAT + TEMPSNF);
                            tempamount = (RATE * Milk_kg).ToString("F2");
                            amount     = Convert.ToDouble(tempamount);
                        }
                        CHARTID = ViewState["cowchartname"].ToString();
                    }
                    //if (NATURE == "Buffalo")
                    //{

                    //    if (charttype == "FAT")
                    //    {
                    //        COUNTI = COUNTI + 1;
                    //        gettingfatratechart();
                    //        RATE = Convert.ToDouble(DTG.Tables[9].Rows[rows][0]);
                    //        commission = Convert.ToDouble(DTG.Tables[9].Rows[rows][1]);
                    //        bonus = Convert.ToDouble(DTG.Tables[9].Rows[rows][2]);
                    //        CHARTID = ViewState["buffchartname"].ToString();
                    //        tempamount = (RATE * Milk_kg).ToString("F2");
                    //        amount = Convert.ToDouble(tempamount);
                    //    }

                    //}
                }

                if (NATURE == "Cow")
                {
                    if ((commission < 0.20) && (commission > 0))
                    {
                        double TEMPFAT = Convert.ToDouble(ViewState["FAT"]);
                        templtr = milkltr;
                        double mkg = templtr * 1.03;
                        calcommission = (RATE * commission) * templtr;
                    }
                    if ((commission >= 0.20) && (commission > 0))
                    {
                        double TEMPFAT = Convert.ToDouble(ViewState["FAT"]);
                        templtr = milkltr;;
                        double mkg = templtr * 1.03;
                        calcommission = (commission * templtr);
                    }

                    calbonus = bonus * templtr;
                }

                else
                {
                    if ((commission < 0.20) && (commission > 0))
                    {
                        double TEMPFAT = Convert.ToDouble(ViewState["FAT"]);
                        templtr = milkltr;
                        double mkg = templtr * 1.03;
                        calcommission = (TEMPFAT * commission) * mkg;
                    }
                    if ((commission >= 0.20) && (commission > 0))
                    {
                        double TEMPFAT = Convert.ToDouble(ViewState["FAT"]);
                        templtr = milkltr;
                        double mkg = templtr * 1.03;
                        calcommission = (commission * mkg);
                    }

                    calbonus = bonus * templtr;
                }
                string TEMPCOMM;
                double getcart;
                double spbonus;
                string temprate;
                if (FAT >= minfat && SNF >= maxfat)
                {
                    TEMPCOMM      = calcommission.ToString("F2");
                    calcommission = Convert.ToDouble(TEMPCOMM);
                    getcart       = Convert.ToDouble(ViewState["cart"]);
                    spbonus       = Convert.ToDouble(ViewState["spbonus"]);
                    calcart       = getcart * milkltr;
                    calspl        = spbonus * milkltr;
                    temprate      = (RATE).ToString("f2");
                    RATE          = Convert.ToDouble(temprate);
                    if (RATE > 0)
                    {
                        amount = Convert.ToDouble(tempamount);
                    }
                    else
                    {
                        amount = 0;
                    }
                }
                else
                {
                    TEMPCOMM      = "0";
                    calcommission = 0;
                    getcart       = 0;
                    spbonus       = 0;
                    calcart       = 0;
                    calspl        = 0;
                    temprate      = "0";
                    RATE          = 0;
                    amount        = Convert.ToDouble(tempamount);
                }
                string     finalinserting = " insert into procurement([Agent_id], [Prdate], [Sessions], [Milk_ltr], [Fat], [Snf], [Rate], [Amount], [Plant_Code], [Route_id], [NoofCans], [Milk_kg], [Clr], [Company_Code], [Ratechart_Id], [Milk_Nature], [ComRate], [SampleId], [Sampleno], [milk_tip_st_time], [milk_tip_end_time], [usr_weigher], [usr_analizer], [fat_kg], [snf_kg], [Truck_id],[Status],[CartageAmount],[SplBonusAmount],[RateStatus])values('" + Getagentid + "','" + prdate + "','" + Sessions + "','" + milkltr + "','" + FAT + "','" + SNF + "' ,'" + RATE + "','" + amount + "','" + pcode + "','" + Route_id + "','" + NoofCans + "','" + Milk_kg + "','" + Clr + "','" + ccode + "','" + CHARTID + "','" + Milk_Nature + "','" + calcommission + "','" + SampleId + "','" + SampleId + "','" + milk_tip_st_time + "','" + milk_tip_end_time + "','" + usr_weigher + "','" + usr_analizer + "','" + fat_kg + "','" + snf_kg + "','" + Truck_id + "','" + 0 + "','" + calcart + "','" + calspl + "','  " + ' ' + "')";
                SqlCommand cmd143         = new SqlCommand(finalinserting, con);
                cmd143.ExecuteNonQuery();
                COUNTI = 0;
                //  rows = rows + 1;
                calcommission = 0;
                DTG.Tables.Clear();
            }
            procurementimport();
            if (procimport == procurement)
            {
                Response.Write("<script language='javascript'>alert('" + Server.HtmlEncode(MESS.save) + "')</script>");
            }

            else
            {
                DateTime dt1 = new DateTime();
                dt1 = DateTime.ParseExact(txt_FromDate.Text, "dd/MM/yyyy", null);
                //dt2 = DateTime.ParseExact(txt_ToDate.Text, "dd/MM/yyyy", null);
                string d1 = dt1.ToString("MM/dd/yyyy");
                string delete;
                delete = "delete   from procurement    where plant_code='" + pcode + "'   and prdate='" + d1 + "'  AND  Sessions='" + ddl_shift.SelectedItem.Text + "' ";
                con    = DB.GetConnection();
                SqlCommand cmd = new SqlCommand(delete, con);
                cmd.ExecuteNonQuery();
                Response.Write("<script language='javascript'>alert('" + Server.HtmlEncode(MESS.Check) + "')</script>");
            }
        }

        else
        {
            Response.Write("<script language='javascript'>alert('" + Server.HtmlEncode(MESS.Check) + "')</script>");
        }
    }